﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GrainManage.Tools;

namespace GrainManage
{
    public class AppSettings
    {
        private const string cmdGet = "SELECT Value FROM AppSettings WHERE Key=?";
        private const string cmdSet = "UPDATE AppSettings SET Value=? WHERE Key=?";
        private const string cmdAdd = "INSERT INTO AppSettings(Key,Value) VALUES(?,?)";

        public static string ImageFilter
        {
            get
            {
                return Get("ImageFilter");
            }
        }

        public static string Get(string key)
        {
            string result = string.Empty;
            var obj = SQLite.ExecuteScalar(cmdGet, key);
            if (obj != null)
            {
                result = Convert.ToString(obj);
            }
            return result;
        }

        public static void Set(string key, string value)
        {
            SQLite.Execute(cmdSet, value, key);
        }

        public static void Add(string key, string value)
        {
            if (SQLite.ExecuteScalar(cmdGet, key) == null)
            {
                SQLite.Execute(cmdAdd, key, value);
            }
        }
    }
}
